
#include <ui_manager.h>
#include <display_manager.h>


static int Default_OnDraw(struct Button *ptButton , PDispBuffer ptDispBuffer)
{
	DrawRegion(&ptButton->tButtonRegion , BUTTON_DEFAULT_COLOR);

	Font_SetSize(ptButton->iFontSize);
	DrawTextInRegion_Central(ptButton->name , &ptButton->tButtonRegion , BUTTON_TEXT_COLOR);
	
	FlushDispRegion(&ptButton->tButtonRegion, ptDispBuffer);
	return 0;
}
static int Default_OnPressed(struct Button *ptButton , PDispBuffer ptDispBuffer , PInputEvent ptInputEvent)
{
	unsigned int dwColor = BUTTON_DEFAULT_COLOR;
	ptButton->status = !ptButton->status;
	if(ptButton->status)
		dwColor = BUTTON_PRESSED_COLOR;
	
	DrawRegion(&ptButton->tButtonRegion , dwColor);
	
	DrawTextInRegion_Central(ptButton->name , &ptButton->tButtonRegion , BUTTON_TEXT_COLOR);
	
	FlushDispRegion(&ptButton->tButtonRegion, ptDispBuffer);
	return 0;
}

void InitButton(PButton ptButton , char * name , PRegion ptRegion , ONEDRAW_FUNC OnDraw , ONPRESSED_FUNC OnPressed)
{
	ptButton->status 		= 0;
	ptButton->name 			= name;
	if (ptRegion)
		ptButton->tButtonRegion = *ptRegion;
	ptButton->OnDraw      	= OnDraw ? OnDraw : Default_OnDraw;
	ptButton->OnPressed		= OnPressed ? OnPressed : Default_OnPressed;
}

